package com.gqz.utils;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 控制器的统一异常处理
 */
@Aspect
@Component
public class WebExceptionAspect {

    @Around("execution(* com.gqz.controller.*.*.*(..))")
    public JsonResult catchException(ProceedingJoinPoint pjp) throws Throwable {
        JsonResult result;
        try {
            result = (JsonResult) pjp.proceed();
        } catch (Exception ex) {
            ex.printStackTrace();
            result = JsonResult.error(ex.getMessage());
        }
        return result;
    }

}
